<template>
	<view class="home-container">
		<!-- 搜索区域 -->
		<searchBar></searchBar>
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="item in swiperList" :key="item.goods_id">
				<image class='swiper-img' :src="item.image_src"></image>
			</swiper-item>
		</swiper>
		<!-- 导航区域 -->
		<view class="nav-box">
			<navigator v-for="(item ,index) in navList" :key="index">
				<image :src="item.image_src" mode=""></image>
			</navigator>
		</view>
		<!-- 楼层区域 -->
		<view class='floor-container'>
			<view class="floor-item" v-for="(item,index) in floorList" :key="index">
				<!-- 顶部 -->
				<image class='title-img' :src="item.floor_title.image_src"></image>
				<!-- 底部 -->
				<view class='bottom-box'>
					<view class="left">
						<image :src="item.product_list[0].image_src"></image>
					</view>
					<view class="right">
						<template v-for="(it,i) in item.product_list">
							<image v-if="i!==0" :src="it.image_src"></image>
						</template>
					</view>
				</view>
			</view>
		</view>
		<!-- 返回顶部 -->
		<view class="to-top" v-show="false" @tap='toTop'>
			<view>^</view>
			顶部
		</view>
	</view>
</template>

<script>
	import searchBar from '../../components/searchBar.vue'
	export default {
		components: {
			searchBar
		},
		data() {
			return {
				// 轮播图数据
				swiperList: [],
				// 导航数据
				navList: [],
				// 楼层数据
				floorList: [],
				// 是否显示返回顶部
				isShow: false
			}
		},
		// 调用接口
		onLoad() {
			// uni.request({
			// 	url:"https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata",
			// 	method:'get',
			// }).then(res=>{
			// 	console.log(res)
			// 	this.swiperList = res[1].data.message
			// })
			// 测试request方法 - 轮播图
			this.$request({
				url: "/home/swiperdata",
				method: "get",
			}).then(res => {
				// console.log('res:',res)
				this.swiperList = res.data.message
			})
			// 导航区域
			this.$request({
				url: "/home/catitems",
				method: 'get'
			}).then(res => {
				// console.log(res)
				this.navList = res.data.message
			})

			// 楼层区域
			this.$request({
				url: "/home/floordata",
				method: 'get'
			}).then(res => {
				// console.log(res)
				this.floorList = res.data.message
			})
		},
		// 滚动事件
		onPageScroll(event) {
			console.log('event:', event)
			if (event.scrollTop >= 200) {
				// 显示
				this.isShow = true
			} else {
				// 隐藏
				this.isShow = false
			}
		},
		methods: {
			toTop() {
				uni.pageScrollTo({
					scrollTop: 0
				})
			}
		}
	}
</script>

<style lang="less">
	page {}

	.home-container {
		.swiper-img {
			display: block;
			width: 100%;
			height: 340rpx;
		}

		.nav-box {
			display: flex;
			height: 194rpx;
			align-items: center;

			navigator {
				flex: 1;
				text-align: center;

				image {
					height: 140rpx;
					width: 128rpx;
				}
			}
		}

		.floor-container {
			.floor-item {
				background-color: #f4f4f4;
			}

			.title-img {
				display: block;
				width: 100%;
				height: 88rpx;
			}

			.bottom-box {
				padding: 20rpx 17rpx;
				padding-right: 0;
				display: flex;

				image {
					width: 232rpx;
				}

				.left {
					image {
						height: 386rpx;
					}

					margin-right: 10rpx;
				}

				.right {
					image {
						height: 188rpx;
						margin-bottom: 10rpx;
						margin-right: 10rpx;
					}
				}
			}
		}

		.to-top {
			width: 90rpx;
			height: 90rpx;
			text-align: center;
			display: flex;
			flex-direction: column;
			border-radius: 50%;
			background-color: #ccc;
			position: fixed;
			right: 17rpx;
			bottom: 40rpx;
			opacity: .5;
		}
	}
</style>
